package com.vietnam.power.persistence;

import java.io.Serializable;

import javax.persistence.*;

import org.hibernate.annotations.Type;

import com.vietnam.power.dao.IAuditTable;

import java.util.Date;
import java.util.List;

/**
 * The persistent class for the product_chat database table.
 * 
 */
@Entity
@Table(name = "product_chat")
public class ProductChat implements Serializable, IAuditTable {
	private static final long serialVersionUID = 1L;
	private Long productChatId;
	private boolean blocked;
	private Date createdDate;
	private byte type;
	private List<ChatMessage> chatMessages;
	private Product product;
	private UserInfo createdBy;

	public ProductChat() {
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "PRODUCT_CHAT_ID")
	public Long getProductChatId() {
		return this.productChatId;
	}

	public void setProductChatId(Long productChatId) {
		this.productChatId = productChatId;
	}

	@Type(type = "true_false")
	public boolean getBlocked() {
		return this.blocked;
	}

	public void setBlocked(boolean blocked) {
		this.blocked = blocked;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "CREATED_DATE")
	public Date getCreatedDate() {
		return this.createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	public byte getType() {
		return this.type;
	}

	public void setType(byte type) {
		this.type = type;
	}

	// bi-directional many-to-one association to ChatMessage
	@OneToMany(mappedBy = "productChat")
	public List<ChatMessage> getChatMessages() {
		return this.chatMessages;
	}

	public void setChatMessages(List<ChatMessage> chatMessages) {
		this.chatMessages = chatMessages;
	}

	public ChatMessage addChatMessage(ChatMessage chatMessage) {
		getChatMessages().add(chatMessage);
		chatMessage.setProductChat(this);

		return chatMessage;
	}

	public ChatMessage removeChatMessage(ChatMessage chatMessage) {
		getChatMessages().remove(chatMessage);
		chatMessage.setProductChat(null);

		return chatMessage;
	}

	// bi-directional many-to-one association to Product
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "PRODUCT_ID")
	public Product getProduct() {
		return this.product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}

	@Override
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "CREATED_BY")
	public UserInfo getCreatedBy() {
		return this.createdBy;
	}

	@Override
	public void setCreatedBy(UserInfo createdBy) {
		this.createdBy = createdBy;
	}

}